// 定义版本类
class Version {
  constructor(major, minor, patch) {
    this.major = major
    this.minor = minor
    this.patch = patch
  }

  // 增加版本号
  increment(type) {
    switch (type) {
      case 'major':
        this.major++
        this.minor = 0
        this.patch = 0
        break
      case 'minor':
        this.minor++
        if (this.patch > 9) {
          this.increment('major')
          break
        }
        this.patch = 0
        break
      case 'patch':
        this.patch++
        if (this.patch > 9) {
          this.increment('minor')
          break
        }
        break
      default:
        throw new Error('Invalid version type')
    }
  }

  // 输出版本号
  toString() {
    return `${this.major}.${this.minor}.${this.patch}`
  }
}

// 定义版本控制类
class VersionControl {
  constructor() {
    this.versions = []
  }

  // 添加版本
  addVersion(version) {
    this.versions.push(version)
  }

  // 获取版本
  getVersion(index) {
    if (index < 0 || index >= this.versions.length) {
      throw new Error('Invalid version index')
    }
    return this.versions[index]
  }

  // 输出所有版本
  printVersions() {
    console.log('All versions:')
    for (let i = 0; i < this.versions.length; i++) {
      console.log(`Version ${i + 1}: ${this.versions[i].toString()}`)
    }
  }
}

// 示例代码
const versionControl = new VersionControl()
module.exports = {
  Version,
  versionControl
}
// const version1 = new Version(1, 0, 0)
// const version2 = new Version(1, 1, 0)
// const version3 = new Version(1, 1, 1)
//
// versionControl.addVersion(version1)
// versionControl.addVersion(version2)
// versionControl.addVersion(version3)
//
// console.log(versionControl.getVersion(0).toString()) // 输出 "1.0.0"
// console.log(versionControl.getVersion(1).toString()) // 输出 "1.1.0"
// console.log(versionControl.getVersion(2).toString()) // 输出 "1.1.1"
//
// versionControl.getVersion(0).increment('minor')
// console.log(versionControl.getVersion(0).toString()) // 输出 "1.1.0"
//
// versionControl.printVersions() // 输出所有版本
